package com.example.booksales.controller;

import com.example.booksales.domain.Employee;
import com.example.booksales.service.impl.EmployeeService;
import com.example.booksales.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/employee")
@Api(tags="员工管理(0613胡宇星)")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @ApiOperation("获得全员工列表(22001010613胡宇星)")
    @GetMapping("/list")
    public AjaxResult list(){
        return AjaxResult.success(employeeService.getAllEmployees());
    }
    @ApiOperation(value = "获取员工详细信息(22001010613胡宇星)", notes = "TODO：取得某个员工的详细信息")
    @ApiImplicitParam(name = "employeeid", value = "员工ID",
            required = true, dataType = "long", paramType = "path",
            dataTypeClass = Long.class)
    @GetMapping(value = "/{employeeid}")
    public AjaxResult getInfo(@PathVariable("employeeid") Long employeeid) {
        return AjaxResult.success(employeeService.selectEmployeeById(employeeid));
    }
    @ApiOperation("新增员工(22001010613胡宇星)")
    @PostMapping
    public AjaxResult add(@RequestBody Employee employee) {
        return AjaxResult.success(employeeService.insertEmployee(employee));
    }
    @ApiOperation("修改员工(22001010613胡宇星)")
    @PutMapping
    public AjaxResult edit(@RequestBody Employee employee) {
        return AjaxResult.success(employeeService.updateEmployee(employee));
    }
    @ApiOperation("删除员工(22001010613胡宇星)")
    @ApiImplicitParam(name = "employeeid", value = "员工ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{employeeid}")
    public AjaxResult remove(@PathVariable Long employeeid) {
        return AjaxResult.success(employeeService.deleteEmployeeById(employeeid));
    }
}
